package net.gxnun.xiaoyuan.message.handler;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import net.gxnun.xiaoyuan.core.message.request.WebsiteJoinMsg;
import net.gxnun.xiaoyuan.core.utils.EncryptUtils;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

@Component
public class WebSiteJoinBusiness{
    
    private Logger log = Logger.getLogger(WebSiteJoinBusiness.class);
    
    public boolean checkJoinMsg(WebsiteJoinMsg msg,String token){
        //对token，timestamp，nonce进行字典排序
        List<String> paramsList = new ArrayList<String>();
        paramsList.add(token);
        paramsList.add(msg.getTimestamp());
        paramsList.add(msg.getNonce());
        Collections.sort(paramsList);
        //转换成字符串
        StringBuffer sb = new StringBuffer();
        for(String str : paramsList){
            sb.append(str);
        }
        //加密字符串
        String enStr = EncryptUtils.make(sb.toString(), "sha-1");
        //判断
        log.debug("系统的："+msg.getSignature());
        log.debug("生成的："+enStr);
        if(enStr.equals(msg.getSignature())){
            return true;
        }
        return false;
    }
    
}
